package com.jxwifi.cloud.quickclean.main;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.address.AddressListActivity;
import com.jxwifi.cloud.quickclean.app.AccountMgr;
import com.jxwifi.cloud.quickclean.app.ClientBasicActivity;
import com.jxwifi.cloud.quickclean.app.PasswordLogin;
import com.jxwifi.cloud.quickclean.utils.ToastUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class EpidemicMaskActivity extends ClientBasicActivity  implements EpidemicMaskView{

    @Bind(R.id.rel_main_null_address)
    RelativeLayout mReMainNullAddress;
    @Bind(R.id.rel_main_address)
    RelativeLayout mRelMainAddress;
    @Bind(R.id.tv_main_address_text)
    TextView mTvMainAddressText;
    @Bind(R.id.tv_main_address_detailed)
    TextView mTvMainAddressDetails;
    @Bind(R.id.et_con_em_phone_name)
    EditText mEtConEmPhoneName;
    @Bind(R.id.et_con_em_phone)
    TextView mEtConEmPhone;

    private EpidemicMaskPresenter mPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_epidemic_mask);
        ButterKnife.bind(this);
        openEventBus();
        mPresenter=new EpidemicMaskPresenter(mBaseContext,this);
        mPresenter.initView();
    }

    @OnClick({R.id.rel_img_back_pressed,R.id.bt_con_em_button,R.id.rel_main_address,R.id.rel_main_null_address})
    void clickCK(View v){
        Intent intent=new Intent();
        switch (v.getId()){
            case R.id.rel_img_back_pressed:
                onBackPressed();
                break;
            case R.id.bt_con_em_button:
                mPresenter.onJudgment();
                break;
            //有地址布局点击操作
            case R.id.rel_main_address:
                intent.setClass(mBaseContext, AddressListActivity.class);
                startActivity(intent);
                break;
            //地址无数据布局点击操作
            case R.id.rel_main_null_address:
                intent.setClass(mBaseContext, AddressListActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void ReceiveSuccess(String Strtitle) {
        Toast toast = Toast.makeText(mBaseContext, Strtitle, Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
        finish();
    }

    @Override
    public TextView getAddressDetails() {
        return mTvMainAddressDetails;
    }

    @Override
    public TextView getAddressText() {
        return mTvMainAddressText;
    }

    @Override
    public RelativeLayout getAddressLayout() {
        return mRelMainAddress;
    }

    @Override
    public RelativeLayout getNullAddress() {
        return mReMainNullAddress;
    }

    @Override
    public EditText getEmPhoneName() {
        return mEtConEmPhoneName;
    }

    @Override
    public TextView getEmPhone() {
        return mEtConEmPhone;
    }

    @Override
    public void onFailure(int errorCode, String msg) {
        Toast toast = Toast.makeText(mBaseContext, msg, Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
    }

    @Override
    public void oninfo() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.getinfo();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.initView();
    }
}
